/**
 * @author Anna-Katharina Wickert 
 * @author Yannic Remmet
 * @author Tobias Trabelsi
 * 
 * @version 
 * @since 27.07.2012
 *
 * @license Beer-Ware License (Revision 42)
 *
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * We wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy us a beer in return.
 * ----------------------------------------------------------------------------
 */
package model;


import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.tree.TreeNode;


public class TreeGroup extends TreeElement{
	private static final long serialVersionUID = -8031158429938299671L;
	private LinkedList<TreeElement> list;
	
	public TreeGroup(String title){
		this(title, null);
	}
	public TreeGroup(String title, TreeElement parent) {
		super(title, parent);
		list = new LinkedList<TreeElement>();
	}
	@Override
	public boolean addChild(TreeElement node) {
		node.setParrent(this);
		list.add(node);
		Collections.sort(list);
		return true;
	}
	
	@Override
	public TreeElement getChildAt(int childIndex) {
		return list.get(childIndex);
	}
	@Override
	public boolean hasChildren() {
		return true;
	}
	@Override
	public int getChildCount() {
		return list.size();
	}
	@Override
	public int getIndex(TreeElement node) {
		return list.indexOf(node);
	}
	@Override
	public int getIndex(TreeNode node) {
		return list.indexOf(node);
	}
	@Override
	public boolean del(TreeElement node) {
		Collections.sort(list);
		return list.remove(node);
	}
	@Override
	public Enumeration<TreeElement> children() {
		// TODO Auto-generated method stub
		return new Enumeration<TreeElement>() {
			Iterator<TreeElement> i = list.iterator();
			@Override
			public TreeElement nextElement() {
				return i.next();
			}
			
			@Override
			public boolean hasMoreElements() {
				return i.hasNext();
			}
		};
	}
	@Override
	public int compareTo(TreeElement o) {
		if (o instanceof TreeItem)
			return -1;
		return(this.toString().compareTo(o.toString()));
	}
	
}


